cmake_minimum_required(VERSION 3.14)

project(toxdesk VERSION 0.1 LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (MSVC)
    # warning level 4 and all warnings as errors
    add_compile_options(/W3 )
    add_compile_definitions(_CRT_SECURE_NO_WARNINGS
        NOMINMAX
        SODIUM_STATIC
        __STDC_CONSTANT_MACROSE)
else()
    add_compile_options(-Wall -Wextra -pedantic -fpermissive)
    add_definitions (-Wno-unused-parameter)
    add_definitions (-Wno-unused-variable)
endif()

include_directories(../../third_party/libvpx
    ../deskcore/audio/include
    ../../third_party/include
    ../deskcore)

link_directories(../../third_party/lib/x64 )


find_package(Qt6 6.2 COMPONENTS Core Quick LinguistTools  QuickControls2  REQUIRED)

#find_package(Qt${QT_VERSION_MAJOR} 6.2 COMPONENTS Core  Quick QuickControls2  LinguistTools REQUIRED)

set(TOXDESK_TS_FILES
    toxdesk_en_001.ts
    toxdesk_zh_CN.ts)

set(PROJECT_SOURCES
    main.cpp
    videosurface.cpp
    ToxMainWnd.cpp
    qml.qrc
    win32_app.rc
    ${TS_FILES}
    )



qt_add_executable(toxdesk
    MANUAL_FINALIZATION
    ${PROJECT_SOURCES}
    )
if(ANDROID)
    # Define target properties for Android with Qt 6 as:
    set_property(TARGET toxdesk APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
        ${CMAKE_CURRENT_SOURCE_DIR}/android)
    # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
endif()

#qt6_add_lupdate(toxdesk TS_FILES ${TOXDESK_TS_FILES})
qt_add_translations(toxdesk TS_FILES ${TOXDESK_TS_FILES})

#qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})


target_compile_definitions(toxdesk
    PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)

if(WIN32)
    set(libpath ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/x64)
    target_link_libraries(toxdesk
        PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick
        toxdesk_static
        ws2_32.lib
        Iphlpapi.lib)
elseif(ANDROID)
    set(libpath ${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/lib/${CMAKE_ANDROID_ARCH_ABI})
    target_link_libraries(toxdesk
        PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick
        toxdesk_static
        ${libpath}/libsodium.a
        ${libpath}/libtoxcore.a
        ${libpath}/libvpx.a
        ${libpath}/libopus.a
        )
else()
    target_link_libraries(toxdesk
        PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick
        toxdesk_static)
endif()

set_target_properties(toxdesk PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    )


qt_import_qml_plugins(toxdesk)
qt_finalize_executable(toxdesk)

